<?php
class Bootstrap_Log {		
	static public function build()	{					
		if(Zend_Registry::isRegistered('log')){
			$log = Zend_Registry::get('log');
		}else{		
			$config = Zend_Registry::get('config');		
				
			$_loglevel = (int)$config->system->log_level;
			$_logfile = LOG_DIR.DIRECTORY_SEPARATOR.substr(Util_TimeMath::getDateTime(),0,10).'.log';
			$_loglevel = min($_loglevel, 7);
			$_loglevel = max($_loglevel, 0);
			$log = new Zend_Log();
			$writer = new Zend_Log_Writer_Stream($_logfile);
			//
			$format = '%timestamp% %priorityName% (%priority%):'.Util_HttpRequest::getIp().' || ';
			$format .='CurrentUrl='.Util_HttpRequest::getCurrentUrl().' || ';
			$format .='PreviousUrl='.Util_HttpRequest::getPreviousUrl().PHP_EOL;
			$format .='%message%' . PHP_EOL;
			$formatter = new Zend_Log_Formatter_Simple($format);
			$writer->setFormatter($formatter);
			$log->addWriter($writer);
			$filter = new Zend_Log_Filter_Priority($_loglevel);
			$log->addFilter($filter);	
		}		
		Zend_Registry::set('log', $log);
		return $log;
	}
}